package cn.com.cetccst.appstore.database.converter;

import androidx.room.TypeConverter;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

import cn.com.cetccst.appstore.database.model.AppModel;

/**
 * 用于数据库非原生类型转换
 */
public class ListPlatformConverter {

    @TypeConverter
    public List<AppModel.PlatformDetail> stringToObject(String value) {
        Type typeToken = new TypeToken<List<AppModel.PlatformDetail>>() {
        }.getType();
        return new Gson().fromJson(value, typeToken);
    }

    @TypeConverter
    public String objectToString(List<AppModel.PlatformDetail> value) {
        return new Gson().toJson(value);
    }

}
